﻿Public Class FormTipoClienteListado
    Dim classController As New Class_RC_Controller.rc_Clientes()

    Private m_frmtipocliente As FrmTipoCliente
    Public Property frmtipocliente() As FrmTipoCliente
        Get
            Return m_frmtipocliente
        End Get
        Set(ByVal value As FrmTipoCliente)
            m_frmtipocliente = value
        End Set
    End Property

    Private Sub Cargartipocliente()
        Dim dt As New DataTable
        dt = classController.get_TipoClientes_All(oiml.dbConn, 0, txtDescripcion.Text)
        dgTipoCliente.DataSource = dt
    End Sub

    Private Sub dgTipoCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgTipoCliente.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub
    Private Sub dgTipoCliente_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTipoCliente.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub FormTipoClienteListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Cargartipocliente()

    End Sub

    Private Sub txtDescripcion_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcion.KeyDown
        If e.KeyCode = Keys.Enter Then
            Cargartipocliente()
        End If
    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgTipoCliente.SelectedRows.Count > 0 Then
                Dim codtipocliente As New Integer
                codtipocliente = dgTipoCliente.SelectedRows(0).Cells(0).Value

                If frmtipocliente Is Nothing Then
                    frmtipocliente = New FrmTipoCliente
                    frmtipocliente.codtipocliente = codtipocliente
                    'If frmServicios.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmtipocliente.ShowDialog()
                    Cargartipocliente()
                    frmtipocliente.Dispose()
                    frmtipocliente = Nothing
                    'End If
                Else
                    frmtipocliente.codtipocliente = codtipocliente
                    frmtipocliente.ShowDialog()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        Cargartipocliente()
    End Sub
End Class